﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Expression.Entity;
using T.ServiceComponent.Database.Service;

namespace T.FAS.Runtime.Expression.Dev.Dao.Logic
{
    public class ExprItemLogic
    {
        public const string userName = "T";
        ExprItemDao exprItemDao = new ExprItemDao();
        ExprFuncItemParamDao exprFuncItemParamDao = new ExprFuncItemParamDao();
        /// <summary>
        /// 新增修改
        /// </summary>
        /// <param name="exprItem"></param>
        public void CreateOrUpdateExprItem(ExprItem exprItem)
        {
            DeleteExprItem(exprItem.ID);
            foreach (var item in exprItem.ExprFuncItemParamList)
            {
                item.ID = Guid.NewGuid().ToString();
            }
            exprFuncItemParamDao.Add(exprItem.ExprFuncItemParamList);
            exprItemDao.Add(new List<object> { exprItem });
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ID"></param>
        public void DeleteExprItem(string ID)
        {
            exprItemDao.Delete(new List<string> { ID });
            exprFuncItemParamDao.Delete(new List<string> { ID });
        }
        /// <summary>
        /// 根据父ID与元数据ID查询
        /// </summary>
        /// <param name="exprItem"></param>
        /// <returns></returns>
        public List<ExprItem> GetExprChildrenItemList(ExprItem exprItem, DateTime? dateTime)
        {
            return exprItemDao.GetExprChildrenItemList(exprItem, dateTime);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="ExprMetaDataID"></param>
        /// <returns></returns>
        public List<ExprItem> GetExprItemList(string ExprMetaDataID)
        {
            return exprItemDao.GetExprItemList(ExprMetaDataID);
        }
    }
}
